import getpath
import os
import logging
import csv
import myglobal
import config_json
from delegates import EditDelegateQt,DateTimeEditDelegateQt,DoubleViewDelegate,FloatEditDelegateQt
import sample
from PyQt5 import QtWidgets,QtCore
from DlgYanghua import DlgYanghua
import openpyxl
import re
import logging
from mydb import MyDB_Base
class SampleWeigt(sample.Sample):
    def __init__(self):
        super().__init__()
        self.V1=None
        self.V2=None
        self.m2=None
        self.m1=None
        self.m0=None
        self.m3=None
        self.m4=None
        self.m5=None
        self.item=None
        pass
class MyDb(MyDB_Base):
    def addOne(self):
        n=SampleWeigt()
        n.sampleid="001"
        return n
    def __init__(self,mainw):
        super().__init__(mainw)
        self.doublefmt="%.6f"
        self.properties = [
            {"ele":None,"delegate":self.editDelegate,'width':130,'attr': "sampleid",'visible':True,  'header': "样品中心编号"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "mass",'visible':True,  'header': "试料质量m"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "V1",'visible':True,  'header': "定容体积V1"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "V2",'visible':True,  'header': "分取体积V2"},
            {"ele":None,"delegate":self.floatEdit,'width':100,'attr': "m2",'visible':True,  'header': "坩埚及沉淀质量m2"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "m1",'visible':True,  'header': "坩埚质量m1"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "m0",'visible':True,  'header': "空白质量m0"},
            {"ele":None,"delegate":self.floatEdit,'width':100,'attr': "m3",'visible':True,  'header': "溶液中残余质量m3"},
            {"ele":None,"delegate":self.floatEdit,'width':90,'attr': "m4",'visible':True,  'header': "干扰物质量m4"},
            {"ele":None,"delegate":self.floatEdit,'width':80,'attr': "m5",'visible':True,  'header': "干扰物质量m5"},
            {"xishu":None,"ele":config_json.setting["weight"]["ele"],"delegate":self.editDelegate,'width':80,'attr': "item",'visible':True,  'header': config_json.setting["weight"]["ele"]},
            {"ele":None,"delegate":self.editDelegate,'width':80,'attr': "beizhu",'visible':True,  'header': "备注"},
        ]
    def contextMenuEvent(self,event):
        pass
    def showColumnMenu(self, pos):
        pass
    def lims(self):
        ffbh = self.mainw.ui.cmb_ffbh.text()
        ff2= self.mainw.ui.cmb_ff2.text()
        js2= self.mainw.ui.cmb_js2.text()
        syy = self.mainw.ui.cmb_syy.text()
        ysry = self.mainw.ui.cmb_ysry.text()
        syyqm = self.mainw.ui.cmb_syyqm.text()
        filepath=self.mainw.xlswidget.lims(ffbh,ff2,js2,syy,syyqm,ysry)
        scrollbar = self.mainw.ui.textEdit.verticalScrollBar()
        scrollbar.setSliderPosition(scrollbar.maximum())                      
        self.mainw.ui.textEdit.insertPlainText(filepath + "\n")
        scrollbar = self.mainw.ui.textEdit.verticalScrollBar()
if __name__=="__main__":
    file = os.path.join(getpath.getpath(), "930.csv")
    config_json.read_setting()
    config_json.setting['database'] = file
    db = MyDb(None)
    objs=db.getDataDays(200)
    for obj in objs:
        print(obj.sampleid)
        for one in obj.items.keys():
            print(one[0]+"_"+one[1],getattr(obj,one[0]+"_"+one[1]))       